home *** CD-ROM | disk | FTP | other *** search
- /*
- ** $VER: format.ped 1.0 (24.8.94) written by Robert Brandner
- **
- ** This macro formats leftaligned the current paragraph
- ** (from the current line to the next empty line).
- */
-
- OPTIONS RESULTS
-
- /* first we get the desired width
- ** from the application's settings.
- */
-
- 'GETATTR' APPLICATION FIELD VAR_RIGHTBORDER VAR WIDTH
-
- /* now we get the current line, strip trailing spaces and tabs,
- ** and compute it's length
- */
-
- 'GETLINE' VAR 'LINE'
- LINE = strip(LINE, T, " "||'09'X)
- len = length(LINE)
-
- /* prevlen is needed for the while-condition
- ** When we join a line with an empty line, len and prevlen
- ** will be the same, in which case we stop, as that means,
- ** that we reached the end of the paragraph.
- */
-
- prevlen = 0
-
- /* the while-loop:
- ** We will leave the loop, when len not greater than prevlen,
- ** which means, that we reached an empty line
- */
-
- do while len > prevlen
-
- /* This loop splits the current line until we get
- ** a line shorter than the desired width.
- */
-
- do while len > WIDTH
-
- /* We move the cursor to the desired right border,
- ** and go to the beginning of the word we find there,
- ** as we don't want to split words.
- */
-
- 'GOTOCOLUMN' WIDTH+1
- 'POSITION EOW'
- 'POSITION SOW'
-
- /* Now we look where we are. If we are at the very
- ** left of the line, this means that there were only
- ** one word from the beginning to column <width>.
- ** In that case, we go to the end of this word, which
- ** leads to a line that is too long, but it is better
- ** than splitting the word.
- */
-
- 'GETCURSORPOS' STEM CPOS.
- if CPOS.COLUMN <= 1 then 'POSITION EOW'
-
- /* Now we split the line at the current column, which
- ** results in a line, shorter than <width> (except for
- ** the case with the very long words) and new line
- ** with the rest of the old line.
- ** The cursor is allready at the beginning of this
- ** new line (due to TEXT NEWLINE)
- */
-
- 'TEXT NEWLINE'
-
- /* Now we get this new line again (could possibly be made in
- ** an other way too), strip spaces off, and compute
- ** it's length.
- */
-
- 'GETLINE' VAR 'LINE'
- LINE = strip(LINE, T, " ")
- len = length(LINE)
- end
-
- /* Here we check if the line is empty, which may happen as a
- ** result of the previous while-loop, and if it's empty, we
- ** leave the outer while-loop immediately.
- */
-
- if len == 0 then leave
-
- /* We remember the length of the current line in <prevlen>.
- ** Now we join the current line (which is shorter than <width>)
- ** and the next line. We insert one blank between the
- ** last word of the current, and the first of the next line.
- ** Then we get this joined line, strip the spaces off, and
- ** compute it's length. If the length is the same as <prevlen>
- ** we know that the following line was empty.
- ** In that case we split the lines again, to keep the empty
- ** line. The while-loop will end in this case too.
- */
-
- prevlen = len
- 'POSITION EOL'
- 'DELETE'
- 'TEXT " "'
- 'GETLINE VAR LINE'
- LINE = strip(LINE, T, " ")
- len = length(LINE)
- if prevlen == len then 'TEXT NEWLINE'
- end
-
- /* And here we are! The paragraph is formated and that's the end of
- ** this macro.
- */
-